package com.im.service.controller;

import com.im.service.common.Result;
import com.im.service.domain.vo.AddressBookVO;
import com.im.service.job.SyncOrgUserJob;
import com.im.service.service.ImOrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liuzhiqiang
 */
@RestController
@RequestMapping("/addressBook")
@CrossOrigin
@Slf4j
@Api(tags = "通讯录")
public class AddressBookController {

    @Autowired
    private ImOrgService imOrgService;

    @Autowired
    private SyncOrgUserJob syncOrgUserJob;

    @PostMapping("/syncOrgUser")
    @ApiOperation(value = "同步组织用户")
    public Result syncOrgUser() {
        syncOrgUserJob.syncOrgUser();
        return Result.ok();
    }

    @GetMapping("/tree")
    @ApiOperation(value = "通讯录")
    public Result<List<AddressBookVO>> tree() {
        List<AddressBookVO> list = imOrgService.tree();
        return Result.okData(list);
    }

}
